Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

color-interpolate

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-interpolate

Pick color from a given color palette by index

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
increased by10.92%
Maintainers
2
Weekly downloads
 
Created
Source

color-interpolate stable

For a given palette, return color by any float index. Useful for interpolating colormaps, color palettes or gradients.

Usage

npm install color-interpolate

const interpolate = require('color-interpolate');

let colormap = interpolate(['black', 'gray', 'white']);
let black = colormap(0); // 'rgb(0, 0, 0)'
let white = colormap(1); // 'rgb(255, 255, 255)'
let gray = colormap(.5); // 'rgb(128, 128, 128)'

API

let palette = require('color-interpolate')(colors)

Create interpolator from a list of colors. Colors can be in any format: CSS color string, array with RGB channel values, object with r, g, b or h, s, l channel values or even a number, see color-parse for reference.

let color = palette(index, fn?)

Get interpolated color from palette by index value within 0..1 range. Pass optional fn interpolation function, by default lerp is used, but smoothstep can be used as an alternative.

Example:

const palettes = require('nice-color-palettes')
const palette = require('color-interpolate')(palettes[32])

let activeColor = palette(.2) // 'rgb(51, 23 47)'
let background = palette(1) // 'rgb(255, 255, 255)'
let foreground = palette(0) // 'rgb(0, 0, 0)'

Credits

Thanks to @mattdesl for interpolation functions and @mikkoh for API insight in interpolation-arrays.

colormap — collection of beautiful colormaps, a good source for palettes.
nice-color-palettes — collection of beautiful color palettes from colourlovers.
color-alpha — change alpha of a color string.
color-spectrum — convert spectrum, like FFT result, to color.
color-space — collection of color space transforms, useful for custom interpolation modes.

© Dmitry Yv. MIT License

Keywords

FAQs

Package last updated on 30 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc